package cn.akwangl.design.pattern.behavioral.state.v1;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 时间枚举
 *
 * @author youyongkun
 * @date 2021/12/6 10:36
 */
public enum HourEnum {
    /**
     * 时间状态.
     */
    WEE_HOURS(LocalDateTime.of(LocalDate.now(), LocalTime.of(3, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(6, 0, 0)), "凌晨"),
    MORN(LocalDateTime.of(LocalDate.now(), LocalTime.of(6, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(8, 0, 0)), "早晨"),
    ANTE_MERIDIEM(LocalDateTime.of(LocalDate.now(), LocalTime.of(8, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(11, 0, 0)), "上午"),
    NOON(LocalDateTime.of(LocalDate.now(), LocalTime.of(11, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(13, 0, 0)), "中午"),
    POST_MERIDIEM(LocalDateTime.of(LocalDate.now(), LocalTime.of(13, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(17, 0, 0)), "下午"),
    DUSK(LocalDateTime.of(LocalDate.now(), LocalTime.of(17, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(19, 0, 0)), "傍晚"),
    NIGHT(LocalDateTime.of(LocalDate.now(), LocalTime.of(19, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(23, 0, 0)), "晚上"),
    LATE_AT_NIGHT(LocalDateTime.of(LocalDate.now(), LocalTime.of(23, 0, 0)),
            LocalDateTime.of(LocalDate.now(), LocalTime.of(3, 0, 0)), "深夜");

    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private String state;

    HourEnum(LocalDateTime startTime, LocalDateTime endTime, String state) {
        this.startTime = startTime;
        this.endTime = endTime;
        this.state = state;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public String getState() {
        return state;
    }

    /**
     * 根据时间获取状态.
     *
     * @param time 当前时间.
     * @return 状态
     * @author youyongkun
     * @date 2021/12/6 11:00
     */
    public static String hourState(LocalDateTime time) {
        for (HourEnum value : HourEnum.values()) {
            LocalDateTime startTime = value.getStartTime();
            LocalDateTime endTime = value.getEndTime();
            if (time.isAfter(startTime) && time.isBefore(endTime)) {
                return value.getState();
            }
        }
        return "未知";
    }
}
